<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .big-box{
            margin: 50px;
        }
        h2{
            text-align: center;
            font-weight: 700;
            line-height: 80px;
        }
        .big-box input{
            box-sizing: border-box;
            padding-left: 30px;
            width: 100%;
            height: 40px;
            border-radius: 5px;
            margin: 20px auto;
        }
        .big-box span{
            position: fixed;
            left: 220px;
            color: aqua;
        }
        .big-box button{
            height: 50px;
            width: 100%;
            background-color: blue;
        }
    </style>
</head>
<body>
    <div class="big-box">
        <h2>登录页</h2>
        <input type="text" placeholder="输入用户名/手机号/邮箱"><br>
        <input type="password" placeholder="输入密码"><br>
        <span>忘记密码？</span><br>
        <button>登录页</button>
    </div>
</body>
</html>
<script src="./04-ajax.js"></script>
<script>
    var inp = document.querySelectorAll('input')
    var btn = document.querySelector('button')
    btn.onclick=function(){
        console.log(111);
        if(inp[0].value &&inp[1].value){
           if( /^1[3-9]\d{9}$/.test( inp[0].value ) &&/^[a-zA-Z0-9_]{4,16}$/.test(inp[0].value)&&/^\w{1,}@[0-9a-z]{1,}\.(com|cn|org)$/.test(inp[0].value)||/^\d{4}$/.test(inp[1].value)){
            ajax('get','https://yantianfeng.com/api/login',{ username:inp[0].value,password: inp[1].value }, function(data){
                        //console.log(data);
                        if( data.status == 200 ){
                            console.log('登陆成功');
                        }else{
                            console.log('登陆失败!');
                        }
                    })
                }else{
                    alert('请输入正确的手机号/密码')
                }
            }else{
                alert('用户名/密码不能为空!')
            }
        }
</script>